<%@ include file="/common/taglibs.jsp"%>

<head>
    <title><fmt:message key="userProfile.title"/></title>
    <meta name="heading" content="<fmt:message key='userProfile.heading'/>"/>
    <meta name="menu" content="UserMenu"/>
    <script type="text/javascript" src="<c:url value='/scripts/selectbox.js'/>"></script>
</head>

<spring:bind path="news.*">
    <c:if test="${not empty status.errorMessages}">
    <div class="error">
        <c:forEach var="error" items="${status.errorMessages}">
            <img src="<c:url value="/images/iconWarning.gif"/>"
                alt="<fmt:message key="icon.warning"/>" class="icon"/>
            <c:out value="${error}" escapeXml="false"/><br />
        </c:forEach>
    </div>
    </c:if>
</spring:bind>


<form:form commandName="news" method="post" action="newsForm.html" onsubmit="return onFormSubmit(this)" id="newsForm">
<form:hidden path="id"/>

<ul>
    <li class="buttonBar right">
        <%-- So the buttons can be used at the bottom of the form --%>
        <c:set var="buttons">
        	<c:choose>
        	<c:when test="${news.id != null}">
            	<input type="submit" class="button" name="update" onclick="bCancel=false" value="<fmt:message key="button.save"/>"/>
			</c:when>
			<c:otherwise>
				<input type="submit" class="button" name="save" onclick="bCancel=false" value="<fmt:message key="button.save"/>"/>
			</c:otherwise>
			</c:choose>
        <c:if test="${param.from == 'list' and param.method != 'Add'}">
            <input type="submit" class="button" name="delete" onclick="bCancel=true;return confirmDelete('user')"
                value="<fmt:message key="button.delete"/>"/>
        </c:if>
            <input type="submit" class="button" name="cancel" onclick="bCancel=true" value="<fmt:message key="button.cancel"/>"/>
        </c:set>
        <c:out value="${buttons}" escapeXml="false"/>
    </li>
    <li>
        <appfuse:label styleClass="desc" key="news.title"/>
        <form:errors path="title" cssClass="fieldError"/>
        <form:input path="title" id="title" cssClass="text large" cssErrorClass="text large error"/>
    </li>
    <li>
         <appfuse:label styleClass="desc" key="news.text"/>
         <form:errors path="text" cssClass="fieldError"/>
         <form:textarea path="text" id="text" cssClass="text medium" cssErrorClass="text medium error" onchange="passwordChanged(this)"/>
    </li>
    <li>
        <appfuse:label styleClass="desc" key="news.datecreation"/>
        <form:errors path="datecreation" cssClass="fieldError"/>
        <form:input path="datecreation" id="datecreation" cssClass="text large" cssErrorClass="text large error"/>
    </li>
    
    <li>
    	<label class="desc" for="group">Gruppo</label>
        <select id="team" name="team">
        	<option value="-1">Globale</option>
        	<c:forEach items="${teams}" var="team">
        		<c:set var="selectedVar"></c:set>
        		<c:forEach items="${teamsSelected}" var="teamSelected">
					<c:if test="${teamSelected.teamid == team.id}">
						<c:set var="selectedVar">SELECTED</c:set>
					</c:if>
        		</c:forEach>
        		<option ${selectedVar} value="${team.id}">${team.label}</option>
        	</c:forEach>
        </select>
    </li>
    
   </ul>
</form:form>

<script type="text/javascript">
    Form.focusFirstElement($('newsForm'));
    highlightFormElements();
</script>

<v:javascript formName="user" staticJavascript="false"/>
<script type="text/javascript" src="<c:url value="/scripts/validator.jsp"/>"></script>

